﻿@model MenuModel
@await Component.InvokeAsync("Widget", new { widgetZone = "header_menu_before" })
@{
    var rootCategories = Model.Categories.ToList();
}
@foreach (var category in rootCategories)
{
    var categoryLineModel = new MenuModel.CategoryLineModel
    {
        Category = category
    };
    <partial name="Partials/CategoryLine.Menu" model="categoryLineModel"/>
}
@if (Model.Brands.Any())
{
    <li class="category -hasSubmenu" text="@Loc["Brands.Menu"]">
        <a href="@Url.RouteUrl("BrandList")">
            <span class="title">@Loc["Brands.Menu"]</span>
        </a>
        <ul>
            @foreach (var brand in Model.Brands)
            {
                <li>
                    <a href="@Url.RouteUrl("Brand", new { brand.SeName })">
                        <span class="title">@brand.Name</span>
                        @if (!string.IsNullOrEmpty(brand.Icon))
                        {
                            <span class="category-icon @brand.Icon"></span>
                        }

                    </a>
                </li>
            }
        </ul>
        <span class="go-back"></span>
        <span class="go-forward"></span>
    </li>
}
@if (Model.Collections.Any())
{
    <li class="category -hasSubmenu" text="@Loc["Collections.Menu"]">
        <a href="#">
            <span class="title">@Loc["Collections.Menu"]</span>
        </a>
        <ul>
            @foreach (var collect in Model.Collections)
            {
                <li>
                    <a href="@Url.RouteUrl("Collection", new { collect.SeName })">
                        <span class="title">@collect.Name</span>
                        @if (!string.IsNullOrEmpty(collect.Icon))
                        {
                            <span class="category-icon @collect.Icon"></span>
                        }

                    </a>
                </li>
            }
        </ul>
        <span class="go-back"></span>
        <span class="go-forward"></span>
    </li>
}
@if (Model.DisplaySearchMenu | Model.DisplayNewProductsMenu | Model.DisplayCustomerMenu | Model.DisplayBlogMenu | Model.DisplayContactUsMenu | Model.Pages.Any())
{
    <li class="other-links">
        <ul>
            @if (Model.DisplayHomePageMenu)
            {
                <li class="home-link">
                    <a href="@Url.RouteUrl("HomePage")">
                        <span class="title">@Loc["HomePage"]</span>
                    </a>
                </li>
            }
            @foreach (var mpage in Model.Pages)
            {
                <li>
                    <a href="@Url.RouteUrl("Page", new { mpage.SeName })">
                        <span class="title">@mpage.Name</span>
                    </a>
                </li>
            }
            @if (Model.NewProductsEnabled && Model.DisplayNewProductsMenu)
            {
                <li>
                    <a href="@Url.RouteUrl("NewProducts")">
                        <span class="title">@Loc["Products.NewProducts"]</span>
                    </a>
                </li>
            }
            @if (Model.DisplaySearchMenu)
            {
                <li>
                    <a href="@Url.RouteUrl("ProductSearch")">
                        <span class="title">@Loc["Search"]</span>
                    </a>
                </li>
            }
            @if (Model.DisplayCustomerMenu)
            {
                <li>
                    <a href="@Url.RouteUrl("CustomerInfo")">
                        <span class="title">@Loc["Account.MyAccount"]</span>
                    </a>
                </li>
            }
            @if (Model.BlogEnabled && Model.DisplayBlogMenu)
            {
                <li>
                    <a href="@Url.RouteUrl("Blog")">
                        <span class="title">@Loc["Blog"]</span>
                    </a>
                </li>
            }
            @if (Model.DisplayContactUsMenu)
            {
                <li>
                    <a href="@Url.RouteUrl("ContactUs")">
                        <span class="title">@Loc["ContactUs"]</span>
                    </a>
                </li>
            }
        </ul>
    </li>
}
@await Component.InvokeAsync("Widget", new { widgetZone = "header_menu_after" })

@{
    var rootCategoriesResponsive = Model.Categories.ToList();
    //name it "Categories" if we have only categories. Otherwise, "Menu"
    var responsiveMenuTitle = rootCategoriesResponsive.Any() && Model.Pages.Any() ? Loc["Categories"] : Loc["Menu"];
}